<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="">
              <a-input placeholder="关键词搜索" v-model="queryParam.queryName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="创建时间">
              <j-date placeholder="请选择创建时间" v-model="queryParam.queryTime"></j-date>
            </a-form-item>
          </a-col>

          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <span style="float: left;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" style="color: #F9D532;width: 80px;height: 36px;background: #333333;border-style: none;">查询</a-button>
              <a-button type="primary" @click="searchReset" style="margin-left: 8px;width: 80px;height: 36px;background: #eae7e7;border-style: none;color: #323232">重置</a-button>
            </span>
          </a-col>

          <div style="float: right;margin-right: 10px;">
            <a-button type="primary" @click="add_category(0)" icon="plus" style="color: #F9D532;width: 110px;height: 36px;background: #333333;border-style: none;float: left;margin-right: 5px;" >新增</a-button>
            <a-upload style="margin-left: 8px;float: left;margin-right: 5px" name="file" :showUploadList="false"
                      :multiple="false"
                      :customRequest="importExcel"
                      :action="importExcelUrl" @change="handleImportExcel">
              <a-button type="primary" style="color: #F9D532;width: 85px;height: 34px;background: #333333;border-style: none;margin-right: 5px" :loading="confirmLoading">导入</a-button>
            </a-upload>
            <a-button type="primary" @click="exportExcel" style="color: #F9D532;width: 85px;height: 34px;background: #333333;border-style: none;float: left;margin-right: 5px">导出</a-button>

          </div>

        </a-row>
      </a-form>
    </div>
    <div style="background: #f2f2f2;height: 10px;width: auto;margin-top: 10px;margin-bottom: 30px;"></div>

    <div>
      <div style="border: none;background-color: #ffffff;padding-bottom: 28px;">
        <!--        <span style="font-size: 16px;float: left;color:#000000;font-weight: bold">品类列表</span>-->
        <a-tabs @change="bubu" style="margin-top: -20px">
          <a-tab-pane tab="刺绣部位" key="1"></a-tab-pane>
          <a-tab-pane tab="刺绣颜色" key="2"></a-tab-pane>
          <a-tab-pane tab="刺绣图片" key="3"></a-tab-pane>
          <a-tab-pane tab="刺绣字体" key="4"></a-tab-pane>
          <a-tab-pane tab="绣字高度" key="5"></a-tab-pane>
        </a-tabs>

<!--        <el-upload class="upload-btn"-->
<!--                   action="https://jsonplaceholder.typicode.com/posts/"-->
<!--                   name="myFileNames"-->
<!--                   multiple-->
<!--                   :limit="6"-->
<!--                   :on-exceed="handleExceed"-->
<!--                   :file-list="fileList"-->
<!--                   :http-request="importExcel" style="float: right;margin-right: 5px">-->
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange" v-show="this.tabs==1" style="margin-top: -20px;">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.img)" icon="img"/>
          </div>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
         <div align="center" style="align-content: center;margin-left: 30px;">
          <a @click="add_category(record)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">编辑</a>
          <a-menu-item style="float: left;margin-left: 10px;">
             <a-popconfirm title="确定删除该部位吗?" @confirm="() => delete_location(record.id)">
                  <a style="font-size: 14px;color: #d29328;">删除</a>
                </a-popconfirm>
          </a-menu-item>
          </div>
        </span>
      </a-table>


      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns2"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange" v-show="this.tabs==2" style="margin-top: -20px;">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.colorImg)" icon="img"/>
          </div>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <div align="center" style="align-content: center;margin-left: 30px;">
          <a @click="add_category(record)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">编辑</a>
          <a-menu-item style="float: left;margin-left: 10px;">
             <a-popconfirm title="确定删除该颜色吗?" @confirm="() => delete_color(record.id)">
                  <a style="font-size: 14px;color: #d29328;">删除</a>
                </a-popconfirm>
          </a-menu-item>
          </div>
        </span>
      </a-table>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns3"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange" v-show="this.tabs==3" style="margin-top: -20px;">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.embroideredImage)" icon="img"/>
          </div>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <div align="center" style="align-content: center;margin-left: 30px;">
          <a @click="add_category(record)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">编辑</a>
          <a-menu-item style="float: left;margin-left: 10px;">
             <a-popconfirm title="确定删除该图片吗?" @confirm="() => delete_xiuziimg(record.id)">
                  <a style="font-size: 14px;color: #d29328;">删除</a>
                </a-popconfirm>
          </a-menu-item>
          </div>
        </span>
      </a-table>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns4"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange" v-show="this.tabs==4" style="margin-top: -20px;">

        <template slot="avatarslot" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.embroideredImage)" icon="img"/>
          </div>
        </template>

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <div align="center" style="align-content: center;margin-left: 30px;">
          <a @click="add_category(record)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">编辑</a>
          <a-menu-item style="float: left;margin-left: 10px;">
             <a-popconfirm title="确定删除该字体吗?" @confirm="() => delete_xiuziimg(record.id)">
                  <a style="font-size: 14px;color: #d29328;">删除</a>
                </a-popconfirm>
          </a-menu-item>
          </div>
        </span>
      </a-table>


      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :columns="columns5"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange" v-show="this.tabs==5" style="margin-top: -20px;">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <div align="center" style="align-content: center;margin-left: 30px;">
          <a @click="add_category(record)" style="float: left;margin-left: 10px;font-size: 14px;color: #d29328;">编辑</a>
          <a-menu-item style="float: left;margin-left: 10px;">
             <a-popconfirm title="确定删除该高度吗?" @confirm="() => delete_xiuzi_height(record.id)">
                  <a style="font-size: 14px;color: #d29328;">删除</a>
                </a-popconfirm>
          </a-menu-item>
          </div>
        </span>
      </a-table>

    </div>

    <AddLocationModule ref="modalForm1" @ok="modalFormOk"></AddLocationModule>
    <AddColorModule ref="modalForm2" @ok="modalFormOk"></AddColorModule>
    <AddXiuziModle ref="modalForm3" @ok="modalFormOk"></AddXiuziModle>
    <AddXiuziHeightModule ref="modalForm5" @ok="modalFormOk"></AddXiuziHeightModule>
    <AddXiuziFontModule ref="modalForm4" @ok="modalFormOk"></AddXiuziFontModule>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {putAction,getFileAccessHttpUrl,httpAction,postAction} from '@/api/manage';
  import JDate from '@/components/jeecg/JDate.vue'
  import '@/assets/less/TableExpand.less'
  import AddLocationModule from './modules/AddLocationModule'
  import AddColorModule from './modules/AddColorModule'
  import AddXiuziModle from './modules/AddXiuziModle'
  import AddXiuziHeightModule from './modules/AddXiuziHeightModule'
  import AddXiuziFontModule from './modules/AddXiuziFontModule'

  export default {
    name: "categoryinfo",
    mixins:[JeecgListMixin],
    components: {
      JDate,
      AddLocationModule,
      AddColorModule,
      AddXiuziModle,
      AddXiuziHeightModule,
      AddXiuziFontModule
    },
    data () {
      return {
        description: 'categoryinfo管理页面',
        tabs: 1,//切换框
        confirmLoading:false,
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'部位名称',
            align:"center",
            dataIndex: 'xiuziLocaltion'
          },
          {
            title:'编号',
            align:"center",
            dataIndex: 'code'
          },
          {
            title:'排序',
            align:"center",
            dataIndex: 'numbers'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],

        columns2: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'颜色名称',
            align:"center",
            dataIndex: 'colorName'
          },
          {
            title:'编号',
            align:"center",
            dataIndex: 'code'
          },
          {
            title: '缩略图片',
            align: "center",
            width: 150,
            dataIndex: 'colorImg',
            scopedSlots: {customRender: "avatarslot"}
          },
          {
            title:'排序',
            align:"center",
            dataIndex: 'numbers'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],

        columns3: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'图片名称',
            align:"center",
            dataIndex: 'embroideredName'
          },
          {
            title:'编号',
            align:"center",
            dataIndex: 'code'
          },
          {
            title: '缩略图片',
            align: "center",
            width: 150,
            dataIndex: 'embroideredImage',
            scopedSlots: {customRender: "avatarslot"}
          },
          // {
          //   title:'高度',
          //   align:"center",
          //   dataIndex: 'xiuziSize'
          // },
          {
            title:'排序',
            align:"center",
            dataIndex: 'numbers'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],

        columns4: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'字体名称',
            align:"center",
            dataIndex: 'embroideredName'
          },
          {
            title:'编号',
            align:"center",
            dataIndex: 'code'
          },
          {
            title: '缩略图片',
            align: "center",
            width: 150,
            dataIndex: 'embroideredImage',
            scopedSlots: {customRender: "avatarslot"}
          },
          // {
          //   title:'高度',
          //   align:"center",
          //   dataIndex: 'xiuziSize'
          // },
          {
            title:'排序',
            align:"center",
            dataIndex: 'numbers'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],

        columns5: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'绣字高度',
            align:"center",
            dataIndex: 'embroideredHeight'
          },
          {
            title:'编号',
            align:"center",
            dataIndex: 'heightCode'
          },
          // {
          //   title:'单位',
          //   align:"center",
          //   dataIndex: 'heightCode',
          //   customRender(index) {
          //     return "cm";
          //   }
          // },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'创建时间',
            align:"center",
            dataIndex: 'createTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            width: 190,
            scopedSlots: { customRender: 'action' },
          }
        ],

        url: {
          list: "/admin/parameter/test_xiuzi_locationlist?category_id="+this.$route.query.category_id,
          delete_xiuzi_location: "/admin/parameter/delete_xiuzi_location",
          delete_xiuzi_color: "/admin/parameter/delete_xiuzi_color",
          delete_xiuzi: "/admin/parameter/delete_xiuzi_fontImg",
          delete_height: "/admin/parameter/delete_xiuzi_height",
          import_xiuzidata: "/admin/ImportData/import_xiuzi_Excel",
        }
      }
    },
    methods: {
      bubu (e) {
        this.total = 0
        this.tabs = e
        if (e == 1) {
          this.url.list = '/admin/parameter/test_xiuzi_locationlist?category_id='+this.$route.query.category_id
        }else if(e == 2){
          this.url.list = '/admin/parameter/test_xiuzi_colorlist?category_id='+this.$route.query.category_id
        }else if(e == 3){
          this.url.list = '/admin/parameter/test_xiuzi_imglist?category_id='+this.$route.query.category_id
        }else if(e == 4){
          this.url.list = '/admin/parameter/test_xiuzi_fontlist?category_id='+this.$route.query.category_id
        }
        else {
          this.url.list = '/admin/parameter/test_xiuzi_hegihtlist?category_id='+this.$route.query.category_id
        }
        this.loadData();
      },
      getAvatarView: function (avatar) {
        return getFileAccessHttpUrl(avatar)
      },
      /**
       * 导入数据
       */
      importExcel(param){
        this.confirmLoading = true;
        let formData = new FormData()
        formData.append('file', param.file);
        formData.append('category_id', this.$route.query.category_id);
        formData.append('type', this.tabs);
        postAction(this.url.import_xiuzidata,formData).then((res)=>{
          if(res.code=='0'){
            this.confirmLoading = false;
            this.$message.success(res.msg);
            this.loadData();
          }else {
            this.confirmLoading = false;
            this.$message.error(res.msg);
          }
        });
      },
      /**
       * 导出
       */
      exportExcel(){
        let url = getFileAccessHttpUrl(window._CONFIG['domianURL'] + "/admin/ExportData/export_xiuzi?category_id=" + this.$route.query.category_id+"&type="+this.tabs)
        window.open(url);
      },
      add_category(record) {
        if(this.tabs==1){
          if(record=='0'){
            this.$refs.modalForm1.edit(record);
            this.$refs.modalForm1.title = "添加绣字部位";
            this.$refs.modalForm1.disableSubmit = true;
          }else {
            this.$refs.modalForm1.edit(record);
            this.$refs.modalForm1.title = "编辑绣字部位";
            this.$refs.modalForm1.disableSubmit = true;
          }
        }else if(this.tabs==2){
          if(record=='0'){
            this.$refs.modalForm2.edit(record);
            this.$refs.modalForm2.title = "添加绣字颜色";
            this.$refs.modalForm2.disableSubmit = true;
          }else {
            this.$refs.modalForm2.edit(record);
            this.$refs.modalForm2.title = "编辑绣字颜色";
            this.$refs.modalForm2.disableSubmit = true;
          }
        }else if(this.tabs==3){
          if(record=='0'){
            this.$refs.modalForm3.edit(record);
            this.$refs.modalForm3.title = "添加绣字图片";
            this.$refs.modalForm3.disableSubmit = true;
          }else {
            this.$refs.modalForm3.edit(record);
            this.$refs.modalForm3.title = "编辑绣字图片";
            this.$refs.modalForm3.disableSubmit = true;
          }
        }else if(this.tabs==4){
          if(record=='0'){
            this.$refs.modalForm4.edit(record);
            this.$refs.modalForm4.title = "添加绣字字体";
            this.$refs.modalForm4.disableSubmit = true;
          }else {
            this.$refs.modalForm4.edit(record);
            this.$refs.modalForm4.title = "编辑绣字字体";
            this.$refs.modalForm4.disableSubmit = true;
          }
        }
        else if(this.tabs==5){
          this.$refs.modalForm5.edit(record);
          this.$refs.modalForm5.title = "绣字高度";
          this.$refs.modalForm5.disableSubmit = true;
        }
      },
      delete_location(id){//删除部位
        let params = {canshu_id:id};
        httpAction(this.url.delete_xiuzi_location,params,"put").then((res)=>{
          if(res.success){
            this.$message.success(res.message);
            this.loadData();
          }else {
            this.$message.error(res.message);
          }
        });
      },
      delete_color(id){//删除颜色
        let params = {canshu_id:id};
        httpAction(this.url.delete_xiuzi_color,params,"put").then((res)=>{
          if(res.success){
            this.$message.success(res.message);
            this.loadData();
          }else {
            this.$message.error(res.message);
          }
        });
      },
      delete_xiuziimg(id){//删除绣字
        let params = {canshu_id:id};
        httpAction(this.url.delete_xiuzi,params,"put").then((res)=>{
          if(res.success){
            this.$message.success(res.message);
            this.loadData();
          }else {
            this.$message.error(res.message);
          }
        });
      },
      delete_xiuzi_height(id){
        let params = {canshu_id:id};
        httpAction(this.url.delete_height,params,"put").then((res)=>{
          if(res.success){
            this.$message.success(res.message);
            this.loadData();
          }else {
            this.$message.error(res.message);
          }
        });
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>